<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>邀请好友</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no">
  <link href="/member/css/style.css" rel="stylesheet" type="text/css">
  <script src="/member/js/index.js" type="text/javascript"></script>
  <script src="/static/mobile/js/jquery-1.8.2.js"></script>
  <script src="/static/mobile/js/Validform_v5.3.2_min.js"></script>
  <script src="/static/mobile/js/Validform_Datatype.js"></script>
  <script src="/static/mobile/js/jquery.form.min.js"></script>
  <script src="/static/mobile/js/layer_mobile/layer.js"></script>
  <script src="/static/mobile/js/layui/layui.js"></script>
</head>
<body>
<div class="wrap">
  <div class="invite_heads">
    <div class="invite_heads_font">邀请好友</div>
    <div class="invite_hints">
      <div class="invite_hint">
        <div class="invite_hint_font"><span class="invite_hint_font1">{$info.nickname} </span>邀请你注册成为善食元会员,快来注册
          加入吧！ 邀请码：<span class="invite_hint_font1">{$info.username}</span></div>
      </div>
    </div>
  </div>
  <div class="invite_centers">
    <form action="{:url('interfaces/member/registers')}" method="post" id="form_2">
    <div class="invite_center">
      <img src="/member/img/invite_06.png" class="invite_center_left">
      <div class="invite_center_right">
        <input type="text" placeholder="请输入手机号" name="username" id="phone">
      </div>
    </div>
    <div class="invite_center">
      <img src="/member/img/invite_07.png" class="invite_center_left">
      <div class="invite_center_right">
        <input type="text" placeholder="请输入验证码" name="code" style="width:180px;">
        <div class="invite_center_right_font" onclick="check_num()" id="yzm_2">获取验证码</div>
      </div>
    </div>
    <div class="invite_center">
      <img src="/member/img/invite_08.png" class="invite_center_left">
      <div class="invite_center_right">
        <input type="text" placeholder="请输入密码" name="password">
      </div>
    </div>
      <input type="hidden" value="{:input('invite_member_id',0)}" name="invite_member_id">
    <div class="invite_center">
      <img src="/member/img/invite_09.png" class="invite_center_left">
      <div class="invite_center_right">
        <input type="text" placeholder="确认密码" name="confirm_password">
      </div>
    </div>
  <button type="submit" class="invite_font" id="sub_2" style="color:#fff;text-align: center;display: block;border: none;">立即注册</button>
  </form>
</div>
</body>
<script>
    var demo2 = $("#form_2").Validform({
        tiptype: function (msg) {
            layer.open({content: msg, skin: 'msg', time:2});
        },
        btnSubmit:'#sub_2',
        tipSweep: true,
        ajaxPost:true,
        callback:function(t){
            console.log(t.message);

            if (t.code == 200){
                layer.open({content:t.message,skin:'msg',time:3});
                window.location.href = "http://xykj399.com/index.php/interfaces/member/choose_system";
                //跳转到个人信息
//                var type = "{:input('type')}";
//                if(type == 'ios'){
//                    window.location.href = "https://www.pgyer.com/7pjm";
//                }
//                if(type == 'android'){
//                    window.location.href = "https://www.pgyer.com/NcF9";
//                }

            }else{
                layer.open({content:t.message,skin:'msg',time:3});
            }
        }
    });
    demo2.config({
        ajaxpost:{
            error: function () {
                layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
            }
        }
    });
    //发送验证码
    function check_num(){
        var tel = $("#phone").val();
        if (tel == ''){
            layer.open({content: '请输入注册账号', skin: 'msg', time:2});
            return false;
        }
        if (!(/^1(3|4|5|7|8)\d{9}$/.test(tel))){
            layer.open({content: '账号格式不正确', skin: 'msg', time:2});
            return false;
        }
        if (!check_unique(tel)){
            return false;
        }
        count_down();
        $.ajax({
            url:"{:url('interfaces/member/get_code')}",
            dataType:'json',
            type:'post',
            data:{'phone':tel,'type':'reg'},
            success:function(t){
                layer.open({content:'发送成功',skin:'msg',time:2});
            }
        })
    }
    //验证码倒计时
    function count_down(){
        var num = 60;
        var verif = $('#yzm_2');
        var timer = setInterval(function(){
            verif.text(num+'秒');
            if (num <=60 && num >= 1){
                verif.removeAttr('href');
            }else{
                verif.text('重新获取验证码');
                window.clearInterval(timer);
                verif.attr("href",'javascript:check_num(this.id);');
            }
            num--;
        },1000);
    }
    //检测注册手机号码的唯一性
    function check_unique(tel){
        var flag = true;
        $.ajax({
            url:"{:url('mobile/shop_set/check_bind_tel')}",
            type:'post',
            async:false,
            dateType:'json',
            data:{'tel':tel},
            success:function(t){
                if (t.code != 200){
                    layer.open({content: t.message,skin: 'msg',time:2});
                    flag = false;
                }
            }
        });
        return flag;
    }
</script>
</html>